package com.remoter.basic.bean;

import java.io.Serializable;

import com.remoter.basic.util.StringUtil;

/**
 * @author			koko
 * @date 			2017-08-08 14:16:43
 * @description 	类功能说明
 */
public abstract class AbstractModule implements Serializable{
	
	private static final long serialVersionUID = -5904211838736441908L;
	
	private String server;
	private String protocol;
	private String host;
	private int port;
	private String type;
	private String bean;
	
	public String getServer() {
		return server;
	}
	public void setServer(String server) {
		this.server = server;
	}
	public String getProtocol() {
		return protocol;
	}
	public void setProtocol(String protocol) {
		this.protocol = protocol;
	}
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getBean() {
		return bean;
	}
	public void setBean(String bean) {
		this.bean = bean;
	}
	
	public String getKey(){
		StringBuilder sb = new StringBuilder("/");
		sb.append(this.server).append("/");
		sb.append(this.type).append("(").append(this.bean).append(":").append(this.protocol).append(")").append("/");
		if(this.isProvider()){
			sb.append("providers/");
		}else{
			sb.append("consumers/");
		}
		sb.append(this.host).append(":").append(this.port);
		return sb.toString();
	}
	
	public abstract boolean isProvider();
	public abstract boolean isConsumer();
	
	@Override
	public int hashCode() {
		return this.getKey().hashCode();
	}

	@Override
	public boolean equals(Object obj){
		if(null == obj){
			return false;
		}
		if(obj instanceof AbstractModule){
			return StringUtil.isEquals(((AbstractModule)obj).getKey(),this.getKey());
		}
		return false;
	}
	
	@Override
	public String toString() {
		return this.getKey();
	}
	
}